package com.witsight.hibernate.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.witsight.hibernate.dao.CityRepository;
import com.witsight.hibernate.model.City;
import com.witsight.hibernate.service.CityService;
import com.witsight.hibernate.service.UserService;
import com.witsight.platform.exception.BusinessException;
import com.witsight.platform.util.tools.SpringUtil;

/**   
 * 说明：[]
 * @Title: CityServiceImpl.java 
 * @Package com.witsight.hibernate.service.impl 
 * @See: []
 * Copyright: Copyright (c) 2017
 * Company:sany huax witsight team by product
 * @author: fuyp  
 * @date: 2017年9月19日 上午11:04:57 
 * @version: V1.0
 *
 */
@Service
public class CityServiceImpl extends JpaBaseGenericServiceImpl<City,String> implements CityService{
	@Autowired
	protected CityServiceImpl(CityRepository baseDao) {
		super(baseDao);
	}
	
	public boolean saveCity() throws BusinessException{
		City city = new City("city", "shanhai1");
		this.getBaseDao().save(city);
//		if (true) {
//			throw new BusinessException("aaaaaa");
//		}
		return true;
	}
	
	public boolean updateCity() throws BusinessException {
		City city = this.getBaseDao().findOne("8a8b409a5e79ec10015e79ec18a20000");
		city.setCountry("test update");
//		this.getBaseDao().save(city);
		return true;
	}
	
	private boolean saveUpCity() throws BusinessException{
		City city = new City("city2", "shanhai");
		this.getBaseDao().save(city);
//		if (true) {
//			throw new BusinessException("aaaaaa");
//		}
		return true;
	}
	public boolean getCity() throws BusinessException{
		UserService userService = SpringUtil.getBeanByType(UserService.class);
		userService.saveUser();
		City city = new City("city1", "shanhai");
		this.getBaseDao().save(city);
		return true;
	}
}
